package utils

import (
	"fmt"
	"github.com/gin-contrib/sessions"
	"github.com/gin-gonic/gin"
)

// SetSession 设置session
func SetSession(c *gin.Context, key, val string, age int) {
	session := sessions.Default(c)
	session.Options(sessions.Options{
		MaxAge: age,
		Path:   "/",
	})
	session.Set(key, val)
	_ = session.Save()
}

// GetSession 获取session
func GetSession(c *gin.Context, key string) string {
	session := sessions.Default(c)
	val := session.Get(key)
	return fmt.Sprintf("%v", val)
}
